package com.hae.shop.micoshopmemberservice.mapper;

import com.hae.shop.micoshopmemberservice.mapper.model.UserTokenDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserTokenMapper {

    @Select("SELECT id as id ,token as token ,login_type as LoginType, device_infor as deviceInfor ,is_availability as isAvailability,user_id as userId"
            + " , create_time as createTime,update_time as updateTime FROM mico_user_token WHERE user_id=#{userId} AND login_type=#{loginType} and is_availability ='0'; ")
    UserTokenDo selectByUserIdAndLoginType(@Param("userId") Long userId, @Param("loginType") String loginType);

    @Update("update mico_user_token set is_availability ='1',update_time=now() where user_id=#{userId} and login_type =#{loginType} ")
    int updateTokenAvailability(@Param("userId") Long userId, @Param("loginType") String loginType);

    @Update("update mico_user_token set is_availability ='1',update_time=now() where token = #{loginType} ")
    int updateTokenAvailabilityByToken(@Param("token") String token);

    @Insert("INSERT INTO `mico_user_token` VALUES (null, #{token},#{loginType}, #{deviceInfor}, 0, #{userId} ,now(), now() ); ")
    int insertUserToken(UserTokenDo userTokenDo);

}
